/*
Input
There are several (about 50, 000) test cases, please process till EOF.
Each test case contains one line with two integers x(1 <= x <= 10) and y(1 <= y <= 109) separated by a single space - the expected number shown on the screen in the end.
Output
For each test case, print the minimal number of pressing of the buttons, or “-1”(without quotes) 
if there’s no way to achieve his goal.

Sample Input
1 1
3 8
9 31
 
Sample Output
0
5
11

Hint
For the second test case, one way to achieve is:
(1, 1) -> (1, 2) -> (2, 4) -> (2, 5) -> (3, 7.5) -> (3, 8.5)

 题意：输入2个数，x，y ；一个是数量x，一个是总价y。有两种操作，一种是数量不变，总价+1，变成x，1+y；
 另一种是数量+1，总价加单价，变成x+1，y+y/x。总价显示的为取整后的整数，小数部分忽略。
 给定一个目标x，y，初始状态为 1，1，求最少需要多少次可以目标状态，不可以达到的话输出-1.
------------------------------------------------------------------
思路：如果数量不变加总价的话，那么单价就会变大，否则的话单价是不变的；那么我们可以用贪心的思想，
让单价尽可能的大，但小于(y+1)/x，即单价的上线，使总价不会超过；贪心的策略是，每次尽量加价格，
加到能满足条件的最大值，然后加一下数量，这样反复直到到达答案。
int ans;
			double kk=(y+1)/x;
	        double cnt=(int)x-1;
	        double tmp=1;
	        for(int i=1;i<=(int)x;i++)
	        {
	            double tt=i*kk;
	            System.out.println(tt);
	            ans=(int)(tt-tmp);
	            tmp+=ans;
	            System.out.println(tmp);
	            tmp=tmp*(i+1)/i;
	            cnt+=ans;
	            System.out.println(ans+","+cnt+","+tmp);
	        }
	        System.out.println(cnt);
 */
package com.yuan.algorithms.practice201505;

import java.util.Scanner;

public class 贪心组合数 {

	static float x, y, m, n,up;
	static int sum;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			x = sc.nextFloat();
			y = sc.nextFloat();
			if (x > y) {
				System.out.println(-1);
				continue;
			}
			m = 1;
			n = 1;
			up = (y + 1) / x;// 单位价格
			sum = 0;// 次数
			while ((int) m <= x && (int) n <= y) {
				if ((int) m == x && (int) n == y) {
					System.out.println(sum);
					break;
				}
				if (m == x) {
					++n;
				} else {
					if ((n + 1) / m < up) {
						++n;
					} else {
						n += n / m;
						++m;
					}
				}
				++sum;
			}
		}
	}

}
